<script>
<?php
require_once('simpletest/autorun.php');
require_once('simpletest/browser.php');

//Simple Unit tests checking Databse connection, inserts removes and correct order
class RegAccountTest extends UnitTestCase {
//covers Code coverage for data as well as constructor
    function testDatabaseConnection (){
        $link = mysql_connect('localhost', 'root', '');
          if (!$link) {
            $this->assertTrue(1==0);
          }
          else{

            $this->assertTrue(1==1);
          }
    }

    //make sure the test db is empty before each test
    function setUp() {
			$link = mysql_connect('localhost', 'root', '');
			if (!$link) {
				die('Not connected : ' . mysql_error());
			}
			$db_selected = mysql_select_db('FinalProject', $link);
			if (!$db_selected) {
				die ('Can\'t use Final Project: ' . mysql_error());
			}
            $query = sprintf("DELETE FROM `Users` WHERE `Fname` = 'testing091231832';");
            // Perform Query
            $result = mysql_query($query);
        }

        function testInsertUser (){
            $browser = new SimpleBrowser();
            $browser->get('http://aspen.local.com/FinalProject/LandingPage/PHP/registerAccount.php?user=testing091231832&Fname=testing091231832&Lname=testing091231832&password=testing091231832');
			$query = sprintf("SELECT * FROM `Users` WHERE `Fname` = 'testing091231832';");

            // Perform Query
            $result = mysql_query($query);

            // Check result
            // This shows the actual query sent to MySQL, and the error. Useful for debugging.
            if (!$result) {
                   $message  = 'Invalid query: '.mysql_error().' ';
                   $message .= 'Whole query: '.$query;
                   die($message);
            }

			//check if the user was added
			$counter = 0;
				while ($row = mysql_fetch_assoc($result)) {
                      $counter=1;
                  }
			$this->assertTrue($counter==1);
			$query = sprintf("DELETE FROM `Users` WHERE `Fname` = 'testing091231832';");
            // Perform Query
            $result = mysql_query($query);
        }
}

?>
</script>